﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Web;
using System.Web.Mvc;
using System.Web.Script.Serialization;

namespace GpUI.Controllers
{
    public class adminController : Controller
    {
        // GET: admin
       // [App_Start.ShowQuan]
        public ActionResult show()//主页显示
        {
            return View();
        }
       // [App_Start.ShowQuan]
        public ActionResult ToMenushow()//显示今日推荐
        {
            return View();
        }
       // [App_Start.ShowQuan]
        public ActionResult ReMenushow()//显示推荐t套餐
        {
            return View();
        }
        //[App_Start.ShowQuan]
        public ActionResult ADDDO(HttpPostedFileBase File)
        {
            string URL="http://localhost:19451/";
            string FileURL = Server.MapPath("/image/");

            string NewUrl = FileURL.Substring(74);
            string FileName = File.FileName;
            File.SaveAs(FileURL + FileName);
            string MenuName = Request["name"];
            decimal MenuPrice =Convert.ToDecimal( Request["price"]);
            string MenuDescrib = Request["JianJie"];
            int Tid =Convert.ToInt32(Request["Sel1"]);
            string MenuPhoto = NewUrl + FileName;
 
            HttpClient client = new HttpClient();
            client.BaseAddress = new Uri(URL);

            var content = new FormUrlEncodedContent(new Dictionary<string, string>()       
                {    
                 
                    {"MenuName",MenuName},
                    {"MenuPhoto",MenuPhoto},
                    {"MenuDescrib",MenuDescrib},
                    {"MenuPrice",MenuPrice.ToString()},
                    {"Tid",Tid.ToString()}
                 });

            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            HttpResponseMessage response = client.PostAsync("api/Menu/PostaddMen",content).Result;


            var result = "";
            if (response.IsSuccessStatusCode)
            {
                result = response.Content.ReadAsStringAsync().Result;

                JavaScriptSerializer Serializer = new JavaScriptSerializer();
                var items = Serializer.DeserializeObject(result);
                return Content("<script>alert('添加成功');location.href='/admin/show'</script>"); 
            }
            return View();
        } 
           
    }
    
}